package com.example.demopoi.schedule;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.Random;

//@Component
public class ArticleViewScheduler {

    @Autowired
    private RestTemplate restTemplate;

    @Scheduled(fixedDelay = 30000)
    public void view() {

        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add(HttpHeaders.USER_AGENT, "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36");
        httpHeaders.add(HttpHeaders.HOST,"blog.csdn.net");
        httpHeaders.add(HttpHeaders.REFERER,"https://blog.csdn.net/zhangkangen");
        httpHeaders.add(HttpHeaders.COOKIE,"uuid_tt_dd=10_6612717290-1533696074312-286881; __yadk_uid=TKmBlWH5tKZQFlIH60az0ztV48tZ5lPJ; smidV2=20180810112255f32d5eac133eb7903cb00e3d7b2d174d003a3f6fc1e683c70; UN=zhangkangen; ADHOC_MEMBERSHIP_CLIENT_ID1.0=28ce4fb9-d118-944a-2f60-3a560730b96a; Hm_ct_6bcd52f51e9b3dce32bec4a3997715ac=1788*1*PC_VC; dc_session_id=10_1535085687573.148546; TY_SESSION_ID=b575e1dd-3be9-4886-bcaf-7d02c6592dd7; UserName=zhangkangen; UserInfo=drt5hdIK7R1uPzvHiGNayJgNHGmEv6ETKmrI3ApYai4Nxn88%2BXPk%2BcGwk%2B34%2BL6FqFSvbAFxDH4z1iwFW7zW0psxu0r2XAatDKZ6cdPc74t%2B8dghvCcl8H0iW2qWgx5aGTYyz11xjTKoGxuWwjEIOQ%3D%3D; UserNick=%E6%B8%BA%E5%B0%8F%E5%BA%B7; AU=32D; BT=1535627374890; UserToken=drt5hdIK7R1uPzvHiGNayJgNHGmEv6ETKmrI3ApYai4Nxn88%2BXPk%2BcGwk%2B34%2BL6FqFSvbAFxDH4z1iwFW7zW0psxu0r2XAatDKZ6cdPc74t%2B8dghvCcl8H0iW2qWgx5abQ5La5bHBy8zMH%2BMh8oBs4aAkOXs3fDq4nwzfPT8tMiyNpwZT7Z%2BXaoMJ%2B26Lf4m; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1535627854,1535627882,1535628435,1535628886; dc_tos=pe9v92; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1535629431");
        HttpEntity<String> entity = new HttpEntity<>("", httpHeaders);

        String url = "https://blog.csdn.net/zhangkangen/article/details/50801958?_rnd=" + new Random().nextGaussian();
        ResponseEntity<String> res = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
        System.out.println(res.getStatusCode());
    }
}
